/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * jifReporteRequerrimientos.java
 *
 * Created on 25-sep-2010, 15:30:22
 */

package Requerrimientos;

import administracion.delegate.GestionPedidosDelegate;
import administracion.helper.Listas;
import administracion.helper.Utiles_MensajesDialogo;
import administracion.propiedades.Propiedades;
import java.awt.event.KeyEvent;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;
import net.sf.jasperreports.engine.JasperPrint;
import net.sf.jasperreports.view.JasperViewer;
import suministros.ejb30.TO.EmpresaTO;

/**
 *
 * @author Diana
 */
public class jifReporteRequerrimientos extends javax.swing.JInternalFrame {
     List<EmpresaTO> empresas;
    /** Creates new form jifReporteRequerrimientos */
    public jifReporteRequerrimientos() {
        this.initComponents();
        empresas = Listas.getEmpresas();
        if(empresas.isEmpty()){
            this.jCheckBox1.setEnabled(false);
        }
        this.jCheckBox1.setSelected(false);
        this.llenarComboEmpresa();
        this.jcbEmpresa.setEnabled(false);
    }
    private void llenarComboEmpresa() {
        empresas = null;
        List listaPaises_cbo = this.cboBeanBindingEmpresa1.getLista();
        listaPaises_cbo.clear();
        try
        {
           if(this.jCheckBox1.isSelected()){
                empresas = Listas.getEmpresas();
            }
            else{
                empresas = Listas.getEmpresaPrincipal();
            }
          this.cboBeanBindingEmpresa1.setLista(empresas);
          this.bindingGroup.bind();
          this.jcbEmpresa.updateUI();
          this.jcbEmpresa.setSelectedIndex(0);
        } catch (Exception ex) {
          Utiles_MensajesDialogo.mensajeAlerta("Error al obtener empresas\n" + ex.getMessage());
          ex.printStackTrace();
          Logger.getLogger(jifReporteSuministrosAprobados.class.getName()).log(Level.SEVERE, null, ex);
        }
      }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {
        bindingGroup = new org.jdesktop.beansbinding.BindingGroup();

        cboBeanBindingEmpresa1 = new administracion.BeanBinding.CboBeanBindingEmpresa();
        buttonGroup1 = new javax.swing.ButtonGroup();
        jbtAceptar = new javax.swing.JButton();
        jButton2 = new javax.swing.JButton();
        jPanel2 = new javax.swing.JPanel();
        jrbTransferencias1 = new javax.swing.JRadioButton();
        jrbTransferencias2 = new javax.swing.JRadioButton();
        jPanel1 = new javax.swing.JPanel();
        jcbEmpresa = new javax.swing.JComboBox();
        jchkInversion = new javax.swing.JCheckBox();
        jCheckBox1 = new javax.swing.JCheckBox();
        jcbAnio = new javax.swing.JComboBox();
        jLabel3 = new javax.swing.JLabel();

        setTitle("REQUERRIMIENTOS APROBADOS POR SUMINISTRO");

        jbtAceptar.setFont(new java.awt.Font("Arial", 1, 12));
        jbtAceptar.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/button_ok.png"))); // NOI18N
        jbtAceptar.setMnemonic('A');
        jbtAceptar.setText("ACEPTAR");
        jbtAceptar.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jbtAceptarActionPerformed(evt);
            }
        });
        jbtAceptar.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jbtAceptarKeyPressed(evt);
            }
        });

        jButton2.setFont(new java.awt.Font("Arial", 1, 12));
        jButton2.setIcon(new javax.swing.ImageIcon(getClass().getResource("/iconoscomb/16x16ozygen/actions/button_cancel.png"))); // NOI18N
        jButton2.setMnemonic('C');
        jButton2.setText("CANCELAR");
        jButton2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jButton2ActionPerformed(evt);
            }
        });

        jPanel2.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "TIPO DE INFORME", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12), new java.awt.Color(0, 0, 255))); // NOI18N

        buttonGroup1.add(jrbTransferencias1);
        jrbTransferencias1.setText("REPORTE DE SUMINISTROS APROBADOS");
        jrbTransferencias1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbTransferencias1ActionPerformed(evt);
            }
        });

        buttonGroup1.add(jrbTransferencias2);
        jrbTransferencias2.setText("REPORTE DE REQUERRIMIENTOS FALTANTES A APROBAR");
        jrbTransferencias2.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jrbTransferencias2ActionPerformed(evt);
            }
        });

        javax.swing.GroupLayout jPanel2Layout = new javax.swing.GroupLayout(jPanel2);
        jPanel2.setLayout(jPanel2Layout);
        jPanel2Layout.setHorizontalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel2Layout.createSequentialGroup()
                .addContainerGap()
                .addGroup(jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addComponent(jrbTransferencias1)
                    .addComponent(jrbTransferencias2))
                .addContainerGap(100, Short.MAX_VALUE))
        );
        jPanel2Layout.setVerticalGroup(
            jPanel2Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, jPanel2Layout.createSequentialGroup()
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                .addComponent(jrbTransferencias1, javax.swing.GroupLayout.PREFERRED_SIZE, 23, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                .addComponent(jrbTransferencias2)
                .addGap(26, 26, 26))
        );

        jPanel1.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "CRITERIOS GENERALES", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, new java.awt.Font("Arial", 1, 12), new java.awt.Color(0, 0, 255))); // NOI18N

        org.jdesktop.beansbinding.ELProperty eLProperty = org.jdesktop.beansbinding.ELProperty.create("${lista}");
        org.jdesktop.swingbinding.JComboBoxBinding jComboBoxBinding = org.jdesktop.swingbinding.SwingBindings.createJComboBoxBinding(org.jdesktop.beansbinding.AutoBinding.UpdateStrategy.READ_WRITE, cboBeanBindingEmpresa1, eLProperty, jcbEmpresa);
        bindingGroup.addBinding(jComboBoxBinding);

        jcbEmpresa.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcbEmpresaKeyPressed(evt);
            }
        });

        jchkInversion.setFont(new java.awt.Font("Arial", 1, 12));
        jchkInversion.setText("DE INVERSION");
        jchkInversion.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jchkInversionActionPerformed(evt);
            }
        });

        jCheckBox1.setFont(new java.awt.Font("Arial", 1, 12));
        jCheckBox1.setText("POR ENCARGO");
        jCheckBox1.addActionListener(new java.awt.event.ActionListener() {
            public void actionPerformed(java.awt.event.ActionEvent evt) {
                jCheckBox1ActionPerformed(evt);
            }
        });

        jcbAnio.setModel(new javax.swing.DefaultComboBoxModel(new String[] { "2009", "2010" }));
        jcbAnio.addKeyListener(new java.awt.event.KeyAdapter() {
            public void keyPressed(java.awt.event.KeyEvent evt) {
                jcbAnioKeyPressed(evt);
            }
        });

        jLabel3.setFont(new java.awt.Font("Arial", 1, 12));
        jLabel3.setText("AÑO:");

        javax.swing.GroupLayout jPanel1Layout = new javax.swing.GroupLayout(jPanel1);
        jPanel1.setLayout(jPanel1Layout);
        jPanel1Layout.setHorizontalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jCheckBox1)
                        .addGap(18, 18, 18)
                        .addComponent(jcbEmpresa, javax.swing.GroupLayout.PREFERRED_SIZE, 263, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addGroup(jPanel1Layout.createSequentialGroup()
                        .addComponent(jchkInversion)
                        .addGap(18, 18, 18)
                        .addComponent(jLabel3)
                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
                        .addComponent(jcbAnio, javax.swing.GroupLayout.PREFERRED_SIZE, 85, javax.swing.GroupLayout.PREFERRED_SIZE)))
                .addContainerGap(23, Short.MAX_VALUE))
        );
        jPanel1Layout.setVerticalGroup(
            jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(jPanel1Layout.createSequentialGroup()
                .addContainerGap(11, Short.MAX_VALUE)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jcbEmpresa, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jCheckBox1))
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(jPanel1Layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jchkInversion)
                    .addComponent(jcbAnio, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addComponent(jLabel3)))
        );

        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
        getContentPane().setLayout(layout);
        layout.setHorizontalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addComponent(jPanel2, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addComponent(jPanel1, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
            .addGroup(layout.createSequentialGroup()
                .addGap(83, 83, 83)
                .addComponent(jbtAceptar)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addComponent(jButton2)
                .addContainerGap(114, Short.MAX_VALUE))
        );
        layout.setVerticalGroup(
            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
            .addGroup(layout.createSequentialGroup()
                .addContainerGap()
                .addComponent(jPanel2, javax.swing.GroupLayout.PREFERRED_SIZE, 86, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addGap(3, 3, 3)
                .addComponent(jPanel1, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                    .addComponent(jButton2)
                    .addComponent(jbtAceptar))
                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
        );

        bindingGroup.bind();

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void jcbAnioKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcbAnioKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jbtAceptar.requestFocus();
        }
}//GEN-LAST:event_jcbAnioKeyPressed

    private void jchkInversionActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jchkInversionActionPerformed

}//GEN-LAST:event_jchkInversionActionPerformed

    private void jcbEmpresaKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jcbEmpresaKeyPressed

}//GEN-LAST:event_jcbEmpresaKeyPressed

    private void jCheckBox1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jCheckBox1ActionPerformed
        if(this.jCheckBox1.isSelected()){
            this.jcbEmpresa.setEnabled(true);
        } else{
            this.jcbEmpresa.setEnabled(false);
        }
        this.llenarComboEmpresa();
    }//GEN-LAST:event_jCheckBox1ActionPerformed

    private void jbtAceptarActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jbtAceptarActionPerformed
        if(this.jrbTransferencias1.isSelected()){
            try{
            JasperViewer jv = null;
            JasperPrint jp = null;
            Map parametros = new HashMap();
            String emp=((EmpresaTO)this.jcbEmpresa.getSelectedItem()).getCodigo();
            parametros.put("ano", this.jcbAnio.getSelectedItem().toString().trim());
            parametros.put("usuario",Propiedades.getUsuario().toString());
            parametros.put("id_empresa", emp);
            if(this.jchkInversion.isSelected()){
                jp=GestionPedidosDelegate.getInstance().generarReporteIngreso("RequerrimientosAprobadosSuministro.jasper", parametros);
            } else{
                jp=GestionPedidosDelegate.getInstance().generarReporteIngreso("RequerrimientosAprobadosSuministrosOperativo.jasper", parametros);
            }
            jv = new JasperViewer(jp, false);
            jv.setExtendedState(javax.swing.JFrame.MAXIMIZED_BOTH);
            jv.setVisible(true);
        }catch (Exception e) {
            Utiles_MensajesDialogo.mensajeError("No se pudo realizar la transaccion");
        }
       }
         if(this.jrbTransferencias2.isSelected()){
             try{
            JasperViewer jv = null;
            JasperPrint jp = null;
            Map parametros = new HashMap();
            String emp=empresas.get(this.jcbEmpresa.getSelectedIndex()).getCodigo();
            parametros.put("ano", this.jcbAnio.getSelectedItem().toString().trim());
            parametros.put("usuario",Propiedades.getUsuario().toString());
            parametros.put("id_empresa", emp);
            if(this.jchkInversion.isSelected()){
                 jp=GestionPedidosDelegate.getInstance().generarReporteIngreso("RequerrimientosPorAprobar.jasper", parametros);
            }
            else{
                 jp=GestionPedidosDelegate.getInstance().generarReporteIngreso("RequerrimientosPorAprobarOperativo.jasper", parametros);
            }
                jv = new JasperViewer(jp, false);
                jv.setExtendedState(javax.swing.JFrame.MAXIMIZED_BOTH);
                jv.setVisible(true);
            }catch (Exception e) {
                Utiles_MensajesDialogo.mensajeError("No se pudo realizar la transaccion");
            }
       }
}//GEN-LAST:event_jbtAceptarActionPerformed

    private void jbtAceptarKeyPressed(java.awt.event.KeyEvent evt) {//GEN-FIRST:event_jbtAceptarKeyPressed
        if (evt.getKeyCode() == KeyEvent.VK_ENTER ){
            this.jbtAceptar.doClick();
        }
}//GEN-LAST:event_jbtAceptarKeyPressed

    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
        int res = javax.swing.JOptionPane.showConfirmDialog( this,"Esta seguro de salir?",
                "Confirmar",javax.swing.JOptionPane.YES_NO_OPTION );
        if(res==javax.swing.JOptionPane.YES_OPTION){
            this.dispose();
        }
}//GEN-LAST:event_jButton2ActionPerformed

    private void jrbTransferencias1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbTransferencias1ActionPerformed

}//GEN-LAST:event_jrbTransferencias1ActionPerformed

    private void jrbTransferencias2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jrbTransferencias2ActionPerformed

}//GEN-LAST:event_jrbTransferencias2ActionPerformed


    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.ButtonGroup buttonGroup1;
    private administracion.BeanBinding.CboBeanBindingEmpresa cboBeanBindingEmpresa1;
    private javax.swing.JButton jButton2;
    private javax.swing.JCheckBox jCheckBox1;
    private javax.swing.JLabel jLabel3;
    private javax.swing.JPanel jPanel1;
    private javax.swing.JPanel jPanel2;
    private javax.swing.JButton jbtAceptar;
    private javax.swing.JComboBox jcbAnio;
    private javax.swing.JComboBox jcbEmpresa;
    private javax.swing.JCheckBox jchkInversion;
    private javax.swing.JRadioButton jrbTransferencias1;
    private javax.swing.JRadioButton jrbTransferencias2;
    private org.jdesktop.beansbinding.BindingGroup bindingGroup;
    // End of variables declaration//GEN-END:variables

}
